package com.uchedao.seller.ui.carlist;

import android.content.Context;
import android.util.Log;

import com.uchedao.seller.ui.carlist.db.CarDbHelper;
import com.uchedao.seller.ui.carlist.entity.BrandEntity;
import com.uchedao.seller.ui.carlist.entity.CityEntity;
import com.uchedao.seller.ui.carlist.entity.ModelEntity;
import com.uchedao.seller.ui.carlist.entity.ProvinceEntity;
import com.uchedao.seller.ui.carlist.entity.SeriesEntity;

import java.util.ArrayList;

/**
 * Created by ZhangZhanghua on 2015/10/24 0024.
 */
public class CarDbUtil {
    private static String HOST = "http://testopenapi.uchedao.com/";
    public static final String URL_BRAND = "base/vehicle/brands";
    public static final String URL_SERIES = "base/vehicle/serieses";
    public static final String URL_MODEL = "base/vehicle/models";
    private static CarDbHelper carDbHelper;
    private static ArrayList<BrandEntity> brandList;
    private static ArrayList<SeriesEntity> seriesList;
    private static ArrayList<ModelEntity> modelList;
    private static ArrayList<ProvinceEntity> provinceList;
    private static ArrayList<CityEntity> cityList;
    private static Context mContext;
    private static long time;
    private static int i = 0;
    private static int j = 0;




//    private static void writeDB() {
//
//        Log.e("db_util", "db operate start");
//        time = System.currentTimeMillis();
//        carDbHelper.beginTransaction();
//        carDbHelper.deleteAllTable();
//
//        for (BrandEntity brand : brandList) {
//            carDbHelper.insertBrand(brand.getId(), brand.getName(), brand.getFull_spell(), brand.getInitial(), brand.getIcon_path(), brand.getIs_hot());
//        }
//
//        for (SeriesEntity series : seriesList) {
//            carDbHelper.insertSeries(series.getId(), series.getBrand_id(), series.getName(), series.getFull_spell(), series.getType_id(), series.getImport_id());
//        }
//
//        for (ModelEntity model : modelList) {
//            carDbHelper.insertModel(model.getId(), model.getSeries_id(), model.getName(), model.getModel_year());
//        }
//
//
//        carDbHelper.setTransactionSuccessful();
//        carDbHelper.endTransaction();
//        time = System.currentTimeMillis() - time;
//        Log.e("db_util", "db operate end " + time);
//    }

    private static void saveLocation() {
        Log.e("db_util", "db operate start");
        time = System.currentTimeMillis();
        carDbHelper.beginTransaction();
        carDbHelper.deleteAllTable();

        for (ProvinceEntity province : provinceList) {
            carDbHelper.insertProvince(province.getId(), province.getName(), province.getFirst_char(), province.getFull_spell());
        }

        for (CityEntity city : cityList) {
            carDbHelper.insertCity(city.getId(), city.getProvince_id(), city.getName(), city.getFirst_char(), city.getFull_spell());
        }
        carDbHelper.setTransactionSuccessful();
        carDbHelper.endTransaction();
        time = System.currentTimeMillis() - time;
        Log.e("db_util", "db operate end " + time);
    }
}
